(function (vc) {
    vc.extends({
        data: {
            prestoreAccountDepositInfo: {
                tel: '',
                ownerId: '',
                owners: [],
                amount: '',
                remark: '',
                acctType: '',
                primeRate: '',
                primeRates: [],
                amtTypes: [],
                amtType: '1001',
                feeConfigs:[],
                configId:'',
            }
        },
        _initMethod: function () {
            vc.getDict('pay_fee_detail', "prime_rate", function (_data) {
                $that.prestoreAccountDepositInfo.primeRates = _data;
            });
            vc.getDict('account_detail', "amt_type", function (_data) {
                $that.prestoreAccountDepositInfo.amtTypes = _data;
            });
        },
        _initEvent: function () {
            vc.on('prestoreAccountDeposit', 'openAddModal', function () {
                $('#prestoreAccountDepositModel').modal('show');
            });
            
            vc.on('prestoreAccountDeposit', 'openAddModalWithParams', function (_param) {
                vc.component.prestoreAccountDepositInfo.acctType ='2003';
                vc.component.prestoreAccountDepositInfo.amount ;
                vc.component.prestoreAccountDepositInfo.ownerId = _param.ownerId;
                $('#prestoreAccountDepositModel').modal('show');
                $that.initConfig();
                vc.getDict('pay_fee_detail', "prime_rate", function (_data) {
                    $that.prestoreAccountDepositInfo.primeRates = _data;
                });
                vc.getDict('account_detail', "amt_type", function (_data) {
                    $that.prestoreAccountDepositInfo.amtTypes = _data;
                });
            });
            
        },
        methods: {
            prestoreAccountDepositValidate() {
                return vc.validate.validate({
                    prestoreAccountDepositInfo: vc.component.prestoreAccountDepositInfo
                }, {
                    'prestoreAccountDepositInfo.amount': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "金额不能为空"
                        },
                        {
                            limit: "money",
                            param: "",
                            errInfo: "金额格式错误"
                        },
                    ],
                    'prestoreAccountDepositInfo.remark': [
                        {
                            limit: "maxLength",
                            param: "200",
                            errInfo: "备注长度不能超过200位"
                        }
                    ],'prestoreAccountDepositInfo.amtType': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "账户变动类型不能为空"
                        },
                         
                    ],'prestoreAccountDepositInfo.configId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "指定费项不能为空"
                        },
                         
                    ],
                });
            },
            saveprestoreAccountDepositInfo: function () {
                if (!vc.component.prestoreAccountDepositValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                vc.component.prestoreAccountDepositInfo.communityId = vc.getCurrentCommunity().communityId;
                vc.http.apiPost(
                    '/account/ownerPrestoreAccount',
                    JSON.stringify(vc.component.prestoreAccountDepositInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#prestoreAccountDepositModel').modal('hide');
                            vc.component.clearprestoreAccountDepositInfo();
                            vc.emit('simplifyAccountDetailManage', 'refresh', {});
                            // vc.toast('预存成功');
                            _data = _json.data;
                            vc.emit('payFeeOrderResult', '_loadReceipt', _data)

                            // return;
                        }
                        vc.toast(_json.msg);
                        // vc.component.prestoreAccountDepositInfo.errorInfo = _json.msg;
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.component.prestoreAccountDepositInfo.errorInfo = errInfo;
                    });
            },
            clearprestoreAccountDepositInfo: function () {
                let _primeRates = $that.prestoreAccountDepositInfo.primeRates;
                // let _amtTypes = $that.prestoreAccountDepositInfo.amtTypes;
                vc.component.prestoreAccountDepositInfo = {
                    tel: '',
                    ownerId: '',
                    owners: [],
                    amount: '',
                    remark: '',
                    primeRate: '',
                    primeRates: _primeRates,
                    // amtType:_amtTypes,
                    amtType:'',
                    feeConfigs:[],
                    configId:'',
                };
            },
            initConfig:function(){
                let param = {
                    params: {
                        page: 1,
                        row: 200,
                        communityId: vc.getCurrentCommunity().communityId,
                        ownerId: $that.prestoreAccountDepositInfo.ownerId,
                    }
                };
                //发送get请求
                vc.http.apiGet('/fee.listFeeConfig',
                    param,
                    function (json) {
                        let _feeConfigInfo = JSON.parse(json);
                        vc.component.prestoreAccountDepositInfo.feeConfigs = _feeConfigInfo.fees;
                    },
                    function () {
                        console.log('请求失败处理');
                        vc.component.prestoreAccountDepositInfo.feeConfigs = [];s
                    }
                );
            },
        }
    });
})(window.vc);